package mapper;

import DO.StudentDO;
import DTO.EditStudentPasswordDTO;
import DTO.PageStudentDTO;
import DTO.StudentLoginDTO;
import VO.StudentVO;
import VO.UserMsgVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import result.Result;

import java.util.List;

@Mapper
public interface studentMapper {

    @Select("select * from student where student_number = #{studentNumber} and password=#{password}")
    StudentDO studentLogin(StudentLoginDTO studentLoginDTO);

    /**
     * 查询这个班级多少人
     */
    Integer getTotalBYId(PageStudentDTO pageStudentDTO);

    /**
     * 分页查询
     * @param pageStudentDTO
     * @return
     */
    List<StudentVO> pageQuery(PageStudentDTO pageStudentDTO);

    /**
     * 新建班级，插入新同学
     * @param studentDoList
     */
    void insert(List<StudentDO> studentDoList);



    /**
     * 根据学号查询学生
     * @param studentNumber
     */
    @Select("select * from student where student_number = #{studentNumber}")
    StudentDO getById(String studentNumber);

    /**
     * 重置学生密码
     * @param id
     * @param defaultPassword
     * @return
     */
    @Update("update student set password = #{defaultPassword} where id = #{id}")
    int resetPassword(Integer id, String defaultPassword);

    /**
     * 删除学生
     * @param id
     */
    @Delete("delete from student where id = #{id}")
    void delectById(Integer id);

    // 根据id获取原密码
    @Select("select password from student where id = #{id}")
    String getPasswordById(Integer id);

    // 修改密码
    @Update("update student set password = #{newPassword} where id = #{id}")
    void editPassword(EditStudentPasswordDTO editStudentPasswordDTO);

    // 根据学生id获取到他的班级id
    @Select("select class_id from student where id = #{userId}")
    Integer getClassIdById(Integer userId);

    @Select("select * from student where class_id = #{class_id}")
    List<StudentDO> getAllById(Integer classId);

    @Select("select id from student where class_id = #{classId}")
    List<Integer> getUserIds(Integer classId);

    @Select("select username,student_number from student where id = #{userId}")
    UserMsgVO getUserMsg(Integer userId);
}
